package com.shuoyue.ycgk.ui.mine.collection;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.QuestionParent;
import com.shuoyue.ycgk.entity.ChapterType;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.List;

import io.reactivex.Observable;

public interface CollectionContract {
    interface View extends BaseView {
        void setTypeList(List<ChapterType> chapterSectionTypes);

        void setQuestions(List<QuestionParent> questionList);

    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void getType(int moduleId) {
            apply(model.getCollectionType(moduleId))
                    .subscribe(new ApiSubscriber<Optional<List<ChapterType>>>(mView, this) {
                        @Override
                        public void onNext(Optional<List<ChapterType>> listOptional) {
                            super.onNext(listOptional);
                            mView.setTypeList(listOptional.getIncludeNull());
                        }
                    });
        }

        public void getQuestions(Integer sectionId ) {
            apply(model.getCollectionQuestion(sectionId))
                    .subscribe(new ApiSubscriber<Optional<List<QuestionParent>>>(mView, this) {
                        @Override
                        public void onNext(Optional<List<QuestionParent>> listOptional) {
                            super.onNext(listOptional);
                            mView.setQuestions(listOptional.getIncludeNull());
                        }
                    });
        }

    }

    class Model extends BaseModel {
        Observable<BaseResult<List<ChapterType>>> getCollectionType(int moduleId) {
            return RetrofitClient.getInstance().getApi().getCollectionType(moduleId);
        }

        Observable<BaseResult<List<QuestionParent>>> getCollectionQuestion(Integer sectionId ) {
            return RetrofitClient.getInstance().getApi().getCollectionQuestion(sectionId );
        }

    }
}
